package org.extreme.model.data.query;

import org.extreme.commons.XRException;
import org.extreme.model.data.stream.DataStream;

public interface QueryExecutor {
	/**
	 * Executes the query and creates a {@link DataStream DataSource} out of the result.
	 * 
	 * @return a {@link DataStream DataSource} wrapping the query execution result.
	 * @throws XRException
	 */
	public DataStream createDataStream() throws XRException;
	
	/**
	 * Closes resources kept open during the data source iteration.
	 * <p/>
	 * This method is called after the report is filled or the dataset is iterated.
	 * If a resource is not needed after the data source has been created, it should be
	 * released at the end of {@link #createDatasource() createDatasource}.
	 */
	public void close();
	
	/**
	 * Cancels the query if it's currently running.
	 * <p/>
	 * This method will be called from a different thread if the client decides to
	 * cancel the filling process.
	 * 
	 * @return <code>true</code> if and only if the query was running and it has been canceled
	 * @throws XRException
	 */
	public boolean cancelQuery() throws XRException;
}
